﻿using System;

namespace LeanEngine.Business.Security
{
    /// <summary>
    /// Represents a behavior that evaluates whether the user has access to an application functionality through the repository.
    /// </summary>
    public sealed class DefaultValidatorBehavior : IValidatorBehavior
    {
        #region Singleton Members

        private static DefaultValidatorBehavior _instance = new DefaultValidatorBehavior();

        private DefaultValidatorBehavior() { }

        /// <summary>
        /// Gets the current instance of the LeanEngine.Business.Security.DefaultValidatorBehavior class.
        /// </summary>
        public static DefaultValidatorBehavior Instance
        {
            get { return _instance; }
        }

        #endregion

        #region IValidatorBehavior Members

        /// <summary>
        /// Evaluates whether the user has access to the application method.
        /// </summary>
        /// <param name="userName">The user name of the user trying to access the application method.</param>
        /// <param name="password">The password of the user trying to access the application method.</param>
        /// <param name="method">The name of the application method that the user is trying to access.</param>
        public bool ValidateAccess(string userName, string password, string method)
        {
            return Data.SecurityRepository.Instance.HasAccess(method, userName, password);
        }

        #endregion
    }
}
